﻿using System;
using System.Xml;
using System.Text;
using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;

namespace CodeBuilder
{
    internal class ProxyHelper
    {
        internal static Binding GetBinding
            (
            )
        {
            BasicHttpBinding binding = new BasicHttpBinding();
            TimeSpan span = new TimeSpan(0, 3, 0);

            binding.Name = "NoConfigBinding";
            binding.CloseTimeout = span;
            binding.OpenTimeout = span;
            binding.ReceiveTimeout = span;
            binding.SendTimeout = span;
            binding.AllowCookies = false;
            binding.BypassProxyOnLocal = false;
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.MaxBufferSize = 2147483647;
            binding.MaxBufferPoolSize = 524288;
            binding.MaxReceivedMessageSize = 2147483647;
            binding.MessageEncoding = WSMessageEncoding.Text;
            binding.TextEncoding = Encoding.UTF8;
            binding.TransferMode = TransferMode.Buffered;
            binding.UseDefaultWebProxy = true;

            binding.ReaderQuotas = new XmlDictionaryReaderQuotas();
            binding.ReaderQuotas.MaxDepth = 32;
            binding.ReaderQuotas.MaxStringContentLength = 2147483647;
            binding.ReaderQuotas.MaxArrayLength = 2147483647;
            binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
            binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;


            binding.Security.Mode = BasicHttpSecurityMode.None;

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
            binding.Security.Transport.Realm = string.Empty;

            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            binding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;

            return binding;
        }

        internal static EndpointAddress GetEndpoint()
        {
            return (new EndpointAddress(
                Config.ServerUrl
                ));
        }
    }
}
